/*
 * File Name: ApplicationList.java
 * Created on: November 13 2007, 02:39 PM
 */

package co.edu.uniandes.intercon.core.model;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;


/**
 * <code>Singleton</code> used to store ...
 * 
 * @author Fabian Gutierrez [fagossa@gmail.com]
 */
public class LocalApplicationList extends Observable {
    
    /*
     * Singleton instance 
     */
    private static LocalApplicationList instance;
    
    /*
     * application list
     */
	private List<BaseDto> applications;
    
    // avoids instantiation outside the class
    private LocalApplicationList() {
    	applications = new ArrayList<BaseDto>();
    }
    
    /** Creates a new instance of Application list */
    public static synchronized LocalApplicationList getInstance() {
        if (instance==null) {
            instance = new LocalApplicationList();
        }
        return instance;
    }
    
    /**
     * Retrieves current application list
     * @return application list
     */
    public List<BaseDto> getApplicationList() {
        return applications;
    }
    
    /**
     * Retrieves an element based on its index
     * @param	row	Element to be retrieved
     * @return	Searched element
     */
    public BaseDto item(int row) {
    	return applications.get(row);
    }
    
    /**
     * Set the current message and notity all the observers of this class about 
     * the change
     * @param   applicationDto	Application to add to the list
     */
    public void addMessage(BaseDto applicationDto) {
    	applications.add(applicationDto);
        super.setChanged();
        super.notifyObservers("LOCAL");
    }

    /**
     * Removes an element in the specified position
     * @param	row	Position of the element to be removed
     */
	public void remove(int row) {
		applications.remove(row);
		super.setChanged();
        super.notifyObservers("LOCAL");
	}
       
}
